Skip to content

Method: static {...}

1: package de.fhdw.gaming.ipspiel23.ht.strategy.impl.mixed;
2:
3: import java.util.List;
4: import java.util.Optional;
5: import java.util.Random;
6: import java.util.function.Supplier;
7:
8: import de.fhdw.gaming.core.domain.GameException;
9: import de.fhdw.gaming.ipspiel23.ht.domain.IHTPlayer;
10: import de.fhdw.gaming.ipspiel23.ht.domain.IHTState;
11: import de.fhdw.gaming.ipspiel23.ht.moves.IHTMove;
12: import de.fhdw.gaming.ipspiel23.ht.moves.factory.IHTMoveFactory;
13: import de.fhdw.gaming.ipspiel23.ht.strategy.impl.HTStrategy;
14:
15: /**
16: *
17: * implements {@link HTStrategy} by choosing one of the three possible answers.
18: *
19: */
20: public class HTMixedStrategy extends HTStrategy {
21:
22: /**
23: * Random to determine the Answer to Choose.
24: */
25: private static final Random RANDOM = new Random();
26:
27: /**
28: * Constructor.
29: *
30: * @param moveFactory moveFactory.
31: */
32: protected HTMixedStrategy(final IHTMoveFactory moveFactory) {
33: super(moveFactory);
34: }
35:
36: @Override
37: public Optional<IHTMove> computeNextMove(final int gameId, final IHTPlayer player, final IHTState state)
38: throws GameException, InterruptedException {
39: final IHTMoveFactory moveFactory = this.getMoveFactory();
40: final List<Supplier<IHTMove>> moveSuppliers = List.of(
41: moveFactory::createHeadsMove,
42: moveFactory::createTailsMove,
43: moveFactory::createEdgeMove);
44: return Optional.of(moveSuppliers.get(RANDOM.nextInt(moveSuppliers.size())).get());
45: }
46: }